function [X, Y]=findInitialSequence(tour, d)
% X are n control points that is in the range of XX-d<=X<=XX+d
% Y are in-between control points, n-1
% three dimension, minimize length
% use cvx for optimization

N=size(tour,1);
XX=tour';
XX=XX(:);

cvx_begin
    variable Y(3*(N-1))
    variable X(3*N);
    variable k
    minimize (k)
    subject to
        for i=1:(N-1)
            norm(X((3*i-2):(3*i))-2*Y((3*i-2):(3*i))+X((3*i+1):(3*i+3)))<=k
        end
        
        for i=1:N
            X((3*i-2):(3*i))<=XX((3*i-2):(3*i))+d;
            X((3*i-2):(3*i))>=XX((3*i-2):(3*i))-d;   
        end
        2*X(4:3*(N-1))==Y(1:3*(N-2))+Y(4:3*(N-1));
cvx_end
